package m202310.d30;

/**
 * @author haocongshun
 * @date 2023/10/30 19:37:29
 */

/**
 * 104. 二叉树的最大深度
 */
public class Q104 {
    public int maxDepth(TreeNode root) {
        int[] ints = new int[1];
        maxDepth(root, 0, ints);
        return ints[0];
    }

    public void maxDepth(TreeNode node, int current, int[] result) {
        if (node == null) {
            result[0] = Math.max(result[0], current);
            return;
        }
        maxDepth(node.left, current + 1, result);
        maxDepth(node.right, current + 1, result);
    }

    public static class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;

        TreeNode() {
        }

        TreeNode(int val) {
            this.val = val;
        }

        TreeNode(int val, TreeNode left, TreeNode right) {
            this.val = val;
            this.left = left;
            this.right = right;
        }
    }

}
